import java.util.Arrays;
import java.util.Comparator;
import java.util.PriorityQueue;

class Card implements Comparable<Card> {
    public int rank; // 数值
    public String suit; // 花色
    public Card(int rank, String suit) {
        this.rank = rank;
        this.suit = suit;
    }

    public boolean equals(Object obj) {
        //自己和自己比较
        if(this==obj) return true;
        //如果比较对象是null，或者是其他类型
        if(obj==null || !(obj instanceof Card)) return false;
        //比较逻辑
        Card c=(Card)obj;
        return rank==c.rank && suit.equals(c.suit);
    }

    @Override
    public int compareTo(Card o) {
        return this.rank-o.rank;
    }

    @Override
    public String toString() {
        return "Card{" +
                "rank=" + rank +
                ", suit='" + suit + '\'' +
                '}';
    }
}

//基于比较器比较
class RankComparator implements Comparator<Card> {
    @Override
    public int compare(Card o1, Card o2) {
        return o2.rank-o1.rank;
    }
}

public class Test {

    public static void main(String[] args) {
        Card[] cards=new Card[3];
        cards[0]=new Card(3,"♠");
        cards[1]=new Card(2,"♠");
        cards[2]=new Card(6,"♠");

        Arrays.sort(cards,new RankComparator());

        System.out.println(Arrays.toString(cards));
    }


    public static void main3(String[] args) {
        Card c1 = new Card(1, "♠");
        Card c2 = new Card(2, "♠");

        RankComparator rc = new RankComparator();
        System.out.println(rc.compare(c1, c2));
    }

    public static void main2(String[] args) {
        Card c1 = new Card(1, "♠");
        Card c2 = new Card(2, "♠");

        System.out.println(c1.compareTo(c2));
    }

    public static void main1(String[] args) {
        Card c1 = new Card(1, "♠");
        Card c2 = new Card(1, "♠");

        System.out.println(c1==c2);
        System.out.println(c1.equals(c2));
    }
}
